﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MySpace.Data;
public partial class Manage_News_Tree : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bdtree();
        }
    }
    protected void bdtree()
    {
        DBHandler dbh = GetHandler.Init();
        dbh.CommandText = "select * from News_big_type";
        DataTable bigctable = dbh.ExecuteDataTable();
        dbh.CommandText = "select * from News_small_type";
        DataTable smalltable = dbh.ExecuteDataTable();
        TreeNode root = new TreeNode("网站");
        root.NavigateUrl = "News_List.aspx";
        TreeView1.Nodes.Add(root);
        foreach (DataRow drb in bigctable.Rows)
        {
            TreeNode bigchild = new TreeNode("[" + drb["bigclassid"] + "]" + drb["bigclassname"].ToString());
            bigchild.NavigateUrl = "News_List.aspx?bigclass=" + drb["bigclassid"].ToString();
            foreach (DataRow drs in smalltable.Rows)
            {
                if (drb["bigclassid"].ToString() == drs["forbigclass"].ToString())
                {
                    TreeNode smallchild = new TreeNode("[" + drs["smallclassid"] + "]" + drs["smallclassname"].ToString());
                    smallchild.NavigateUrl = "News_List.aspx?smallclass=" + drs["smallclassid"].ToString();
                    bigchild.ChildNodes.Add(smallchild);
                }
            }
            root.ChildNodes.Add(bigchild);
        }
    }
}